{extend name="base"}
{block name="pageBody"}

<section class="content-wrapper">
	<div class="content-container container">
		<div class="main">
			<h1 class="page-title">创建新账户</h1>
			<div class="fieldset">
	            <h2 class="legend">账户信息</h2>
	            <form id="register">
				<ul class="form-list">
					<li class="fields">
						<div class="customer-name">
							<div class="input-box name-firstname">
								<label for="firstname">账户名称<em>*</em></label>
								<input type="text" class="required-entry input-text" name="user_name">
							</div>
							<div class="input-box name-lastname">
								<label for="lastname">手机号<em>*</em></label>
								<input type="text" class="required-entry input-text" name="user_phone">
							</div>
							<div class="clear"></div>
						</div>
	                </li>		
				</ul>
				<h2 class="legend">登录凭证</h2>
				<ul class="form-list">
					<li>
						<div class="input-box">
							<label class="required" for="email_address">邮箱<em>*</em></label>
							<input type="text" class="input-text validate-email required-entry" name="user_email">
						</div>
						<div class="clear"></div>
					</li>
					<li class="fields">
						<div class="customer-name">
							<div class="input-box name-firstname">
								<label for="firstname">密码<em>*</em></label>
								<input type="password" class="required-entry input-text" name="user_password">
							</div>
							<div class="input-box name-lastname">
								<label for="lastname">重复密码<em>*</em></label>
								<input type="password" class="required-entry input-text" id="repass">
							</div>
							<div class="clear"></div>
						</div>
					</li>
				</ul>
				</form>
				<div class="buttons-set">
					<p class="required">* 为必填项</p>
					<a href="login.html" title="Back" class="f-left">&laquo; 返回登录</a>
					<a style="background-color: #B80000" class="colors-btn" onclick="register()">注册</a>
					<div class="clear"></div>
				</div>
        </div>
		</div>
		<div class="clearfix"></div>
		<div class="news-letter-container">
			<div class="free-shipping-block">
				<h1>ENJOY FREE SHIPPING</h1>
				<p>on all orders as our holiday gift for you!</p>
			</div>
		</div>	
	</div>
</section>

<script>
	function register(){
	  var password = $("#register input[name='user_password']").val();
	  var repassword = $("#repass").val();
	  if(password != repassword){
	  	alert("两次密码不同！");
	  	$("#register input[name='user_password']").val("");
	    $("#repass").val("");
	    $("#register input[name='user_password']").focus();

	  	return false;
	  }else{
	      var form = new FormData(document.getElementById("register"));
	      $.ajax({
	          url:"{:url('userdo/Register')}",
	          type:"post",
	          data:form,
	          processData: false,                // jQuery不要去处理发送的数据
	          contentType: false,
	          dataType: 'json',
	                success:function(data){
	                    if (0 == data.code){
	                    	window.location.href="login";
	                    }else{
	                      	alert(data.msg);
	                    }
	                }
	            });
	      } 
    }
</script>
{/block}